//
//  MLeaksMessenger.m
//  MLeaksFinder
//
//  Created by 佘泽坡 on 7/17/16.
//  Copyright © 2016 zeposhe. All rights reserved.
//

#import "MLeaksMessenger.h"

//static __weak UIAlertView *alertView;

@implementation MLeaksMessenger

+ (void)alertWithTitle:(NSString *)title message:(NSString *)message {
    [self alertWithTitle:title message:message delegate:nil additionalButtonTitle:nil];
}
+ (void)alertWithTitle:(NSString *)title
               message:(NSString *)message
              delegate:(id<UIAlertViewDelegate>)delegate
 additionalButtonTitle:(NSString *)additionalButtonTitle {
    [self writeConfigFileTitle:title AndMessage:message];
}
#pragma mark - 修改可控制字段 - wgh
+ (void)writeConfigFileTitle:(NSString *)title AndMessage:(NSString *)message
{
    NSMutableDictionary *dictM = [NSMutableDictionary dictionaryWithCapacity:3];
    [dictM setObject:title ? title : @"" forKey:@"title"];
    [dictM setObject:message ? message : @"" forKey:@"message"];
    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY/MM/dd hh:mm:ss"];
    NSString *dateString = [dateFormatter stringFromDate:currentDate];
    // 时间
    [dictM setObject:dateString forKey:@"time"];
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) ; //得到documents的路径，为当前应用程序独享
    NSString *documentD = [paths objectAtIndex:0];
    NSString *configFile = [documentD stringByAppendingPathComponent:@"ghLeakDebug.plist"];
    NSMutableArray *arrayM = [NSMutableArray array];
    [arrayM addObjectsFromArray:[NSArray arrayWithContentsOfFile:configFile]];
    [arrayM insertObject:dictM atIndex:0];
    [arrayM writeToFile:configFile atomically:YES];
}

@end
